home *** CD-ROM | disk | FTP | other *** search
/ Creative Review 28 / Creative-Review-CD-ROM-28.iso / pc / kungfu / assets / game.dir / 00022_Script_sound manager class < prev    next >
Text File  |  1997-08-08  |  6KB  |  293 lines

  1. -- sound class 
  2. -- --------------------------------------------------
  3.  
  4. property q
  5. property qflag
  6.  
  7. property streams
  8.  
  9. property moves
  10.  
  11. property slaps
  12.  
  13. property streampath
  14.  
  15. property channel
  16. property updategap
  17.  
  18. property max
  19.  
  20. global gtime, gcallback
  21. -- ==================================================
  22. -- new method
  23. -- --------------------------------------------------
  24. on new me
  25.   
  26.   minit me
  27.   return me
  28.   
  29. end mnew 
  30.  
  31. -- ==================================================
  32. -- minit method
  33. -- --------------------------------------------------
  34. on minit me
  35.   
  36.   set moves = data2list ( "move sound compile data")
  37.   set slaps = data2list ( "slap sound compile data")
  38.   set streams = data2list ( "stream sound data" )
  39.   
  40.   if the machinetype = 256 then
  41.     set platformseperator = "\"
  42.   else 
  43.     set platformseperator = ":"
  44.   end if
  45.   
  46.   set streampath = the moviepath  & "audio" & platformseperator
  47.   
  48.   set channel = 1
  49.   
  50.   set q = []
  51.   set qflag = false
  52.   
  53.   set updategap = 20
  54.   
  55.   set max = 3
  56.   
  57. end minit
  58.  
  59. -- ==================================================
  60. -- mmove  method
  61. -- --------------------------------------------------
  62. on mmove me, who, move
  63.   
  64.   --  put "in mmove sound manager", who,  move
  65.   
  66.   set wholist = getaprop ( moves, who )
  67.   set currentsound = getaprop  ( wholist, move )
  68.   
  69.   --  put "currentsound:" , currentsound
  70.   
  71.   if stringp ( currentsound ) then
  72.     mplay me, currentsound
  73.   else if listp ( currentsound ) then
  74.     set chosensound = getat ( random ( count ( currentsound ) ) )
  75.     mplay me, chosensound
  76.   end if
  77.   
  78.   --  put "out mmove sound manager" , currentsound
  79.   
  80. end mmove
  81.  
  82. -- ==================================================
  83. -- mslap method
  84. -- --------------------------------------------------
  85. on mslap me, who
  86.   
  87.   --   put "in mslap sound manager class :"  , who
  88.   
  89.   set wholist = getaprop ( slaps, who )
  90.   set currentsound = getaprop  ( wholist, random ( count ( wholist ) ) )
  91.   
  92.   if stringp ( currentsound ) then
  93.     mplay me, currentsound
  94.   end if
  95.   
  96.   -- put "out mslap sound manager class :"
  97.   
  98. end mslap
  99.  
  100. -- ==================================================
  101. -- mback method
  102. -- --------------------------------------------------
  103. on mback me,  loop
  104.   
  105.   put "in mback sound manager class :"
  106.   
  107.   if the machinetype = 256 then 
  108.     
  109.     set the movierate of sprite 40 = 1
  110.     
  111.   else
  112.     
  113.     if stringp ( loop ) then
  114.       sound stop 3
  115.       puppetsound 3, loop
  116.     end if
  117.     
  118.   end if
  119.   
  120.   put "out mback sound manager class :"
  121.   
  122. end mback
  123.  
  124. -- ==================================================
  125. -- mstopback method
  126. -- --------------------------------------------------
  127. on mstopback me
  128.   
  129.   --  put "in mstopback sound manager"
  130.   
  131.   if the machinetype = 256 then 
  132.     
  133.     set the movierate of sprite 40 = 0
  134.     
  135.   else
  136.     
  137.     sound stop 3
  138.     
  139.   end if
  140.   
  141.   --  put "out mstopback sound manager"
  142.   
  143. end mstopback
  144.  
  145. -- ==================================================
  146. -- msoundbusy method
  147. -- --------------------------------------------------
  148. on msoundbusy me
  149.   
  150.   -- put "in msoundbusy sound manager"
  151.   
  152.   if qflag then return false
  153.   
  154.   if soundbusy ( 1 ) then return true
  155.   if soundbusy ( 2 ) then return true
  156.   
  157.   return false
  158.   
  159.   -- put "out msoundbusy sound manager"
  160.   
  161. end msoundbusy
  162.  
  163. -- ==================================================
  164. -- mstream method
  165. -- --------------------------------------------------
  166. on mstream me, data
  167.   
  168.   --  put "in mstream sound manager class :", data
  169.   
  170.   set currentsound = getaprop  ( streams, data )
  171.   
  172.   if not ( stringp ( currentsound ) ) then return 
  173.   
  174.   --  put streampath & currentsound
  175.   
  176.   sound stop 1
  177.   sound stop 2
  178.   
  179.   mstopback me
  180.   
  181.   memptyq me
  182.   
  183.   updatestage
  184.   
  185.   if stringp ( currentsound ) then
  186.     sound playfile 2, streampath & currentsound
  187.   end if
  188.   
  189.   
  190.   --  put "out mstream sound manager class :"
  191.   
  192. end mstream
  193.  
  194. -- ==================================================
  195. -- mstop method
  196. -- --------------------------------------------------
  197. on mstop me
  198.   
  199.   sound stop 1
  200.   sound stop 2
  201.   sound stop 3
  202.   
  203. end mstop
  204.  
  205. -- ==================================================
  206. -- mplay method
  207. -- --------------------------------------------------
  208. on mplay me, newsound
  209.   
  210.   -- put "in mplay sound manager class :"
  211.   
  212.   if qflag or soundbusy ( channel ) then
  213.     maddq ( me, newsound )
  214.   else 
  215.     puppetsound ( channel, newsound ) 
  216.   end if
  217.   
  218.   -- put "out mplay sound manager class :"
  219.   
  220. end mplay 
  221.  
  222.  
  223. -- ==================================================
  224. -- maddq method
  225. -- --------------------------------------------------
  226. on maddq me, newsound
  227.   
  228.   --  put "in maddq sound manager class :"
  229.   
  230.   if not ( qflag ) then
  231.     set qflag = true
  232.     maddtask gtime, me, the timer
  233.   end if
  234.   
  235.   add q, newsound
  236.   
  237.   --  put "out maddq sound manager class :"
  238.   
  239. end maddq
  240.  
  241. -- ==================================================
  242. -- mdotask method
  243. -- --------------------------------------------------
  244. on mdotask me
  245.   
  246.   --  put "in mdotask sound manager class :"
  247.   
  248.   if ( mcheckq ( me ) ) then return updategap
  249.   else return false
  250.   
  251.   --  put "out mdotask sound manager class :"
  252.   
  253. end mdotask
  254.  
  255. -- ==================================================
  256. -- memptyq method
  257. -- --------------------------------------------------
  258. on memptyq me
  259.   
  260.   set q = []
  261.   set qflag = false
  262.   mdeletetasks gtime, me
  263.   return false
  264.   
  265. end mempty
  266.  
  267. -- ==================================================
  268. -- mcheckq method
  269. -- --------------------------------------------------
  270. on mcheckq me
  271.   
  272.   --  put "in mcheckq sound manager class :"
  273.   
  274.   set newsound = getat ( q , 1 )
  275.   puppetsound channel, newsound
  276.   deleteat ( q, 1 )
  277.   
  278.   if count ( q ) > max then set q = []
  279.   
  280.   if not ( count ( q ) ) then
  281.     set qflag = false
  282.     mdeletetasks gtime, me
  283.     return false
  284.   end if
  285.   
  286.   return true
  287.   
  288.   --  put "out mcheckq sound manager class :"
  289.   
  290. end mcheckq
  291.  
  292.  
  293.